package com.woniuxy.micromemberserver.controller;

import com.github.pagehelper.PageInfo;
import com.slsupermarket.common.res.ResponseMsg;
import com.woniuxy.micromemberserver.bean.MemberBean;
import com.woniuxy.micromemberserver.bean.PageRequest;
import com.woniuxy.micromemberserver.service.IMemberService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会员表现层
 * @Author hz
 */
@RequestMapping("/member")
@RestController
public class MemberController {

    @Resource
    private IMemberService memberServiceImpl;

    /**
     * 条件分页查询
     * @param request
     * @param memberBean
     * @return
     */
    @GetMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg findAll(PageRequest request,@RequestBody MemberBean memberBean){
        PageInfo<MemberBean> pageInfo = memberServiceImpl.findAllByParams(request,memberBean);
        System.out.println(pageInfo);
        return ResponseMsg.builder().code(200).msg("查询").data(pageInfo.getList()).build();
    }

    /**
     * 新增会员
     * @param memberBean
     * @return
     */
    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg save(@RequestBody MemberBean memberBean){
        memberServiceImpl.saveMember(memberBean);
        return ResponseMsg.builder().code(200).msg("新增").build();
    }

    /**
     * 修改会员（或删除：仅修改删除标记）
     * @param memberBean
     * @return
     */
    @PutMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg update(@RequestBody MemberBean memberBean){
        memberServiceImpl.updateMember(memberBean);
        return ResponseMsg.builder().code(200).msg("修改").build();
    }

}
